import type { Linter } from 'eslint';

import { interopDefault } from '../util';

export async function perfectionist(): Promise<Linter.Config[]> {
  const perfectionistPlugin = await interopDefault(import('eslint-plugin-perfectionist'));

  return [
    perfectionistPlugin.configs['recommended-natural'],
    {
      rules: {
        'perfectionist/sort-exports': [
          'error',
          {
            order: 'asc',
            type: 'natural',
          },
        ],
        'perfectionist/sort-imports': [
          'error',
          {
            customGroups: {
              type: {
                'vben-core-type': ['^@vben-core/.+'],
                'vben-type': ['^@vben/.+'],
                'eacloud-type': ['^@eacloud/.+'],
                'vue-type': ['^vue$', '^vue-.+', '^@vue/.+'],
              },
              value: {
                vben: ['^@vben/.+'],
                eacloud: ['^@eacloud/.+'],
                'vben-core': ['^@vben-core/.+'],
                vue: ['^vue$', '^vue-.+', '^@vue/.+'],
              },
            },
            environment: 'node',
            groups: [
              ['external-type', 'builtin-type', 'type'],
              'vue-type',
              'vben-type',
              'vben-core-type',
              'eacloud-type',
              ['parent-type', 'sibling-type', 'index-type'],
              ['internal-type'],
              'builtin',
              'vue',
              'vben',
              'vben-core',
              'eacloud',
              'external',
              'internal',
              ['parent', 'sibling', 'index'],
              'side-effect',
              'side-effect-style',
              'style',
              'object',
              'unknown',
            ],
            internalPattern: ['^#/.+'],
            newlinesBetween: 'always',
            order: 'asc',
            type: 'natural',
          },
        ],
        'perfectionist/sort-modules': 'off',
        'perfectionist/sort-named-exports': [
          'error',
          {
            order: 'asc',
            type: 'natural',
          },
        ],
        // 'perfectionist/sort-objects': [
        //   'off',
        //   {
        //     customGroups: {
        //       items: 'items',
        //       list: 'list',
        //       children: 'children',
        //     },
        //     groups: ['unknown', 'items', 'list', 'children'],
        //     ignorePattern: ['children'],
        //     order: 'asc',
        //     type: 'natural',
        //   },
        // ],
        'perfectionist/sort-objects': 'off', // 源改 取消 对象 强制排序
        'perfectionist/sort-switch-case': 'off', // 源改 取消 switch 强制排序
        'perfectionist/sort-enums': 'off', // 源改 取消 enums 强制排序
        'perfectionist/sort-interfaces': 'off', // 源改 取消 interface 强制排序
        'perfectionist/sort-classes': 'off', // 源改 取消 class 强制排序
        'perfectionist/sort-object-types': 'off', // 源改 取消 对象中的属性类型 强制排序
      },
    },
  ];
}
